/**
 * 
 */
package cn.jhz.filesharingsystem.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.jhz.filesharingsystem.model.Pager;
import cn.jhz.filesharingsystem.model.SharedFile;

/**
 * SharedFileDao的实现类
 * @author asus
 */
@Repository("sharedFileDao")
public class SharedFileDaoImpl extends BaseDaoImpl<SharedFile> implements SharedFileDao {
	
	@Override
	public List<SharedFile> getAllFile(){
		String hql = "FROM SharedFile";
		return super.list(hql, null, null);
	}
	
	@Override
	public Pager<SharedFile> getAllPagerFile(String filename, int provider, boolean state){
		String hql = "FROM SharedFile f WHERE 1=1";
		if(filename != null && !"".equals(filename))
			hql += " and f.fileName like '%"+filename+"%'";
		if(provider > 0 && !state) {
			hql += "and f.provider = "+provider;
		}else if(provider > 0 && state) {
			hql += "and f.state = 1 OR f.provider="+provider+"AND f.state = 0";
		}
		return super.find(hql, null, null);
	}

}
